# coding=utf-8
import encoder
import decoder

import argparse


# parser = argparse.ArgumentParser()
# parser.add_argument('-k', '--k', type=int, help='Number of blocks necessary to reconstruct the original data')
# parser.add_argument('-n', '--n', type=int, help='Total number of total blocks')
# parser.add_argument('directory', help='Directory to encode or Directory to save restored backup if -r is set')
# parser.add_argument('-r', '--restore', action='store_true', default=False)
# args = parser.parse_args()

# restore = args.restore
# k = args.k
# n = args.n
# path = args.directory
# suffix = '.fec'
#
# if not restore:
#     enc = encoder.Encoder(k, n, path, './encoded_dir/', suffix)
#     print('Path to encode' + path)
#     print('Path to encoded files: ./encoded_dir/')
#     print('Number of blocks necessary to reconstruct the original data: ' + str(k))
#     print('Total number of blocks: ' + str(n))
#     enc.encode_directory()
#     print('Encoding complete')
# else:
#     restore_path = path
#     print('Decoding files')
#     dec = decoder.Decoder('./encoded_dir/', './decoded_dir/')
#     dec.decode_directory()
#     print('Decoded to path: decoded_dir/')


if __name__ == '__main__':
    restore = int(input("是否解码(0/1): "))
    k = int(input("Number of blocks necessary to reconstruct the original data: "))
    n = int(input("Total number of total blocks: "))
    path = raw_input("Directory to encode or Directory to save restored backup if 是否解码 is 1: ")
    suffix = '.fec'

    if not restore:
        enc = encoder.Encoder(k, n, path, './encoded_dir/', suffix)
        print('Path to encode' + path)
        print('Path to encoded files: ./encoded_dir/')
        print('Number of blocks necessary to reconstruct the original data: ' + str(k))
        print('Total number of blocks: ' + str(n))
        enc.encode_directory()
        print('Encoding complete')
    else:
        restore_path = path
        print('Decoding files')
        dec = decoder.Decoder(restore_path, './decoded_dir/')
        dec.decode_directory()
        print('Decoded to path: decoded_dir/')
